mutations.js ➔ updateComment   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.216

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 8
ccs 2
cts 5
cp 0.4
crap 1.216
rs 9.4285
c 1
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A mutations.js ➔ ... ➔ state.comments.forEach 0 6 2
1
import Vue from 'vue';
2
3 4
export const setConfig = function(state, config) {
4
	Vue.set(state, 'config', Object.assign({}, state.config, config));
5
};
6
7 4
export const setLastCommentTime = function(state) {
8
	state.lastCommentTime = new Date();
9
};
10
11 4
export const setMaxDepth = function(state, depth) {
12 4
	if (typeof depth !== 'number') {
13
		throw 'Depth must be an integer';
14
	}
15
16
	state.maxDepth = depth;
17
};
18
19 4
export const setOrderBy = function(state, orderBy) {
20
	state.orderBy = orderBy;
21
};
22
23 4
export const orderByNewest = function(state) {
24
	state.orderBy = 'newest';
25
};
26
27 4
export const oderByOldest = function(state) {
28
	state.orderBy = 'oldest';
29
};
30
31 4
export const setUser = function(state, user) {
32
	Vue.set(state, 'user', user);
33
};
34
35 4
export const addComment = function(state, comment) {
36
	let comments = state.comments;
37
38
	comment.created = new Date(comment.created);
39
	comments.push(comment);
40
41
	Vue.set(state, 'comments', comments);
42
};
43
44 4
export const deleteComment = function(state, comment) {
45
	let comments = state.comments.filter(function(commentFromList) {
46
		return commentFromList.id !== comment.id;
47
	});
48
	Vue.set(state, 'comments', comments);
49
};
50
51 4
export const updateComment = function(state, editedComment) {
52
	state.comments.forEach(function(comment) {
53 4
		if (comment.id == editedComment.id) {
54
			let index = state.comments.indexOf(comment);
55
			state.comments[index] = editedComment;
56
		}
57
	});
58
};
59
60 4
export const updatePagination = function(state, data) {
61 2
	let key = data.model + data.modelId + data.parentId;
62 2
	let pagination = Object.assign({}, state.pagination);
63 2
	pagination[key] = data.pagination;
64
65 2
	Vue.set(state, 'pagination', pagination);
66
};
67
68 4
export const clearComments = function(state) {
69
	Vue.set(state, 'comments', []);
70
};
71